<template>
  <a-drawer
      :title="title"
      :width="800"
      placement="right"
      :closable="false"
      @close="close"
      :visible="visible"
  >

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="公司ID">
          <a-input placeholder="请输入公司ID" v-decorator="['companyid', validatorRules.companyid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="统一信用代码">
          <a-input placeholder="请输入统一信用代码" v-decorator="['companycode', validatorRules.companycode ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="公司全称">
          <a-input placeholder="请输入公司全称" v-decorator="['companyname', validatorRules.companyname ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="公司简称">
          <a-input placeholder="请输入公司简称" v-decorator="['companyabbr', validatorRules.companyabbr ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="一句话简介">
          <a-input placeholder="请输入一句话简介" v-decorator="['companybrief', validatorRules.companybrief ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="法人">
          <a-input placeholder="请输入法人" v-decorator="['legalperson', validatorRules.legalperson ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="注册资本">
          <a-input placeholder="请输入注册资本" v-decorator="['registeredamt', validatorRules.registeredamt ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="实缴资本">
          <a-input placeholder="请输入实缴资本" v-decorator="['paidinamt', validatorRules.paidinamt ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="经营范围">
          <a-input placeholder="请输入经营范围" v-decorator="['businessscope', validatorRules.businessscope ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="成立日期">
          <a-input placeholder="请输入成立日期" v-decorator="['registereddate', validatorRules.registereddate ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="所属园区">
          <a-input placeholder="请输入所属园区" v-decorator="['highteckparkid', validatorRules.highteckparkid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="所在城市">
          <a-input placeholder="请输入所在城市" v-decorator="['cityid', validatorRules.cityid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="注册区/县">
          <a-input placeholder="请输入注册区/县" v-decorator="['registereddistrictid', validatorRules.registereddistrictid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="注册详细地址">
          <a-input placeholder="请输入注册详细地址" v-decorator="['registeredaddress', validatorRules.registeredaddress ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="办公区/县">
          <a-input placeholder="请输入办公区/县" v-decorator="['officedistrictid', validatorRules.officedistrictid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="办公详细地址">
          <a-input placeholder="请输入办公详细地址" v-decorator="['officeaddress', validatorRules.officeaddress ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="办公与注册是否一致">
          <a-input placeholder="请输入办公与注册是否一致" v-decorator="['isregoffsame', validatorRules.isregoffsame ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="经营状态">
          <a-input placeholder="请输入经营状态" v-decorator="['operationstatusid', validatorRules.operationstatusid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="所属行业">
          <a-input placeholder="请输入所属行业" v-decorator="['industryid', validatorRules.industryid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="行业标签">
          <a-input placeholder="请输入行业标签" v-decorator="['industrytagid', validatorRules.industrytagid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否高新企业">
          <a-input placeholder="请输入是否高新企业" v-decorator="['ishigtech', validatorRules.ishigtech ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否有BP">
          <a-input placeholder="请输入是否有BP" v-decorator="['isbp', validatorRules.isbp ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="团队标签">
          <a-input placeholder="请输入团队标签" v-decorator="['teamtag', validatorRules.teamtag ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="团队描述">
          <a-input placeholder="请输入团队描述" v-decorator="['teamremark', validatorRules.teamremark ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="人员规模">
          <a-input placeholder="请输入人员规模" v-decorator="['staffsizeid', validatorRules.staffsizeid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="纳税规模">
          <a-input placeholder="请输入纳税规模" v-decorator="['taxedsizeid', validatorRules.taxedsizeid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="估值规模">
          <a-input placeholder="请输入估值规模" v-decorator="['valuationsizeid', validatorRules.valuationsizeid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="融资轮次">
          <a-input placeholder="请输入融资轮次" v-decorator="['refinanceroundid', validatorRules.refinanceroundid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="互动周期">
          <a-input placeholder="请输入互动周期" v-decorator="['interactivecycleid', validatorRules.interactivecycleid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="服务状态">
          <a-input placeholder="请输入服务状态" v-decorator="['servicestatusid', validatorRules.servicestatusid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="Linker">
          <a-input placeholder="请输入Linker" v-decorator="['linkerid', validatorRules.linkerid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="最近更新人">
          <a-input placeholder="请输入最近更新人" v-decorator="['updatebyid', validatorRules.updatebyid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="最近更新日期">
          <a-input placeholder="请输入最近更新日期" v-decorator="['ts', validatorRules.ts ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="状态">
          <a-input placeholder="请输入状态" v-decorator="['datastatus', validatorRules.datastatus ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="互动标签">
          <a-input placeholder="请输入互动标签" v-decorator="['interactivetag', validatorRules.interactivetag ]" />
        </a-form-item>
		
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "CompanyInfoModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        companyid:{rules: [{ required: true, message: '请输入公司ID!' }]},
        companycode:{rules: [{ required: true, message: '请输入统一信用代码!' }]},
        companyname:{rules: [{ required: true, message: '请输入公司全称!' }]},
        companyabbr:{rules: [{ required: true, message: '请输入公司简称!' }]},
        companybrief:{rules: [{ required: true, message: '请输入一句话简介!' }]},
        legalperson:{rules: [{ required: true, message: '请输入法人!' }]},
        registeredamt:{rules: [{ required: true, message: '请输入注册资本!' }]},
        paidinamt:{rules: [{ required: true, message: '请输入实缴资本!' }]},
        businessscope:{rules: [{ required: true, message: '请输入经营范围!' }]},
        registereddate:{rules: [{ required: true, message: '请输入成立日期!' }]},
        highteckparkid:{rules: [{ required: true, message: '请输入所属园区!' }]},
        cityid:{rules: [{ required: true, message: '请输入所在城市!' }]},
        registereddistrictid:{rules: [{ required: true, message: '请输入注册区/县!' }]},
        registeredaddress:{rules: [{ required: true, message: '请输入注册详细地址!' }]},
        officedistrictid:{rules: [{ required: true, message: '请输入办公区/县!' }]},
        officeaddress:{rules: [{ required: true, message: '请输入办公详细地址!' }]},
        isregoffsame:{rules: [{ required: true, message: '请输入办公与注册是否一致!' }]},
        operationstatusid:{rules: [{ required: true, message: '请输入经营状态!' }]},
        industryid:{rules: [{ required: true, message: '请输入所属行业!' }]},
        industrytagid:{rules: [{ required: true, message: '请输入行业标签!' }]},
        ishigtech:{rules: [{ required: true, message: '请输入是否高新企业!' }]},
        isbp:{rules: [{ required: true, message: '请输入是否有BP!' }]},
        teamtag:{rules: [{ required: true, message: '请输入团队标签!' }]},
        teamremark:{rules: [{ required: true, message: '请输入团队描述!' }]},
        staffsizeid:{rules: [{ required: true, message: '请输入人员规模!' }]},
        taxedsizeid:{rules: [{ required: true, message: '请输入纳税规模!' }]},
        valuationsizeid:{rules: [{ required: true, message: '请输入估值规模!' }]},
        refinanceroundid:{rules: [{ required: true, message: '请输入融资轮次!' }]},
        interactivecycleid:{rules: [{ required: true, message: '请输入互动周期!' }]},
        servicestatusid:{rules: [{ required: true, message: '请输入服务状态!' }]},
        linkerid:{rules: [{ required: true, message: '请输入Linker!' }]},
        updatebyid:{rules: [{ required: true, message: '请输入最近更新人!' }]},
        ts:{rules: [{ required: true, message: '请输入最近更新日期!' }]},
        datastatus:{rules: [{ required: true, message: '请输入状态!' }]},
        interactivetag:{rules: [{ required: true, message: '请输入互动标签!' }]},
        },
        url: {
          add: "/robot/companyInfo/add",
          edit: "/robot/companyInfo/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'companyid','companycode','companyname','companyabbr','companybrief','legalperson','registeredamt','paidinamt','businessscope','registereddate','highteckparkid','cityid','registereddistrictid','registeredaddress','officedistrictid','officeaddress','isregoffsame','operationstatusid','industryid','industrytagid','ishigtech','isbp','teamtag','teamremark','staffsizeid','taxedsizeid','valuationsizeid','refinanceroundid','interactivecycleid','servicestatusid','linkerid','updatebyid','ts','datastatus','interactivetag'))
		  //时间格式化
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              // that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>